<template>
       <div>
           <el-form :inline="true" :model="adder" class="demo-form-inline">
               <el-form-item label="用户名：">
                   <el-input v-model="adder.addresslistUser" placeholder="用户名"></el-input>
               </el-form-item>
               <el-form-item label="号码：">
                   <el-input v-model="adder.addresslistCellphonenumber" placeholder="号码"></el-input>
               </el-form-item>
               <el-form-item>
                   <el-button type="primary" @click="GetAdmAddresslist">查询</el-button>
               </el-form-item>
           </el-form>
           <el-table :data="adders.slice((currentPage-1)*pagesize,currentPage*pagesize)" height="500" border style="width: 100%">
               <el-table-column label="用户名" prop="addresslistUser"></el-table-column>
               <el-table-column label="通讯录姓名" prop="addresslistName"></el-table-column>
               <el-table-column label="手机" prop="addresslistCellphonenumber"></el-table-column>
               <el-table-column label="固定电话" prop="addresslistTelephone"></el-table-column>
               <el-table-column label="状态" prop="addresslistState"></el-table-column>
               <el-table-column  label="操作">
                   <template  slot-scope="emp">
                       <el-button icon="el-icon-search" circle size="mini" type="success" @click="GetAdmAddresslistById(emp)"></el-button>
                       <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="GetAdmAddreById(emp)"></el-button>
                       <el-button type="danger" icon="el-icon-delete" circle size="mini" @click="DelByid(emp)"></el-button></template>
               </el-table-column>
           </el-table>
           <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="currentPage"
                   :page-sizes="[5, 10, 20, 40]"
                   :page-size="pagesize"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="adders.length">
           </el-pagination>
           <el-dialog
                   :visible.sync="dialogVisible"
                   width="50%">
                <adm :adde="adde"></adm>
           </el-dialog>
           <el-dialog
                   :visible.sync="dialogVisible1"
                   width="50%">
               <admadd :adde="adde" :dialogV="dialogVisible1" @coles="coles" @update="update"></admadd>
           </el-dialog>
       </div>
</template>

<script>
    import adm from "../../../components/gsl/AdmAddresslist/AdmAddressistById.vue"
    import admadd from "../../../components/gsl/AdmAddresslist/AdmAddreAdd.vue"
    import adder from "../../../model/gsl/AdmAddresslist/adm_addresslist.js"
    const em = adder.getInstance();
    export default{
        components:{adm,admadd},
        data() {
            return {
                currentPage:1, //初始页
                pagesize:10,    //    每页的数
                dialogVisible:false,
                dialogVisible1:false,
                adders:[],
                adder:{},
                adde:{},
            };
        },
        created(){
                //后台请求数据
                this.GetAdmAddresslist();
            },
        methods: {
            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
            GetAdmAddresslist() {
                em.list(this.adder).then((response) => {
                    this.adders = response.data.data;
                    this.adder ={}
                })
            },
            GetAdmAddreById(ad){

                em.listId(ad.row.id).then((response) => {
                    this.adde = response.data.data;
                    this.dialogVisible1=true;
                })

            },
            GetAdmAddresslistById(adde) {
                em.listId(adde.row.id).then((response) => {
                    this.adde = response.data.data;
                    this.dialogVisible=true;
                })
            }, DelByid(emp) {
                console.log(emp.row.id)
                em.remove(emp.row.id).then((re) => {
                   if (re.data.data==1){
                       this.$message.success({
                           message:'删除成功',
                           duration:1000
                       })
                       this.GetAdmAddresslist();
                   }else {
                       this.$message.success({
                           message:'删除失败',
                           duration:1000
                       })
                       this.GetAdmAddresslist();
                   }
                })
            },
            coles(a){
                this.dialogVisible1=a;
            },
            update(a){
                em.update(a).then((response) => {
                    if (response.data.data==1) {
                        this.$message.success({
                            message:'修改成功',
                            duration:1000
                        })
                        this.dialogVisible1=false
                        this.GetAdmAddresslist();

                    }else {
                        alert("修改失败！")
                    }
                })
            }
        }
    }
</script>
